package tokens;

import java.util.ListIterator;
import java.util.Queue;
import java.util.Stack;

import resourceManager.ResourceManager;

import nodes.AbstractNode;
import nodes.command.CommandNode;

/**
 * 
 * @author Charlie Hatcher
 * 
 */

public class CommandToken extends AbstractBinaryToken {

	private String myName;
	private static final String COMMAND_REGEX = "[a-zA-Z][\\w]*";
	private static final String VARIABLE_IDENTIFIER = ":";

	public CommandToken(String name) {
		myName = name;
	}

	public CommandToken() {
	};

	@Override
	public boolean matchToken(String str, ListIterator<String> it) {
		return (str.matches(COMMAND_REGEX) && str.charAt(0) != VARIABLE_IDENTIFIER
				.charAt(0));
	}

	@Override
	public String toString() {
		return syntaxBundle.getString("command_label");
	}

	public AbstractNode process() {
		return new CommandNode(myName, myModel);
	}

	@Override
	public void handleParser(String str, ListIterator<String> it,
			Stack<AbstractBinaryToken> opStack,
			Queue<AbstractNode> outPutQueue, Queue<AbstractNode> queue)
			throws Exception {
		outPutQueue.add((new CommandToken(str)).process());
	}

}
